 import {
   getElHeightRpx,
 } from "../../utils/dom"
 import {
   SUB_PAGES
 } from '../../config/router.config'
 import {
   createStoreBindings
 } from 'mobx-miniprogram-bindings'
 import {
   workOrderSerachIndexStore
 } from '../../store/workOrderSerachIndexStore'
 import {
   workOrderSearchIndexFilterStore
 } from "../../store/workOrderSearchIndexFilterStore"
 import {
   WorkOrderSearchApi
 } from "../../common/apis/workOrder"
 const app = getApp()

 Page({

   /**
    * 页面的初始数据
    */
   data: {
     bodyHeight: 0,
     dataList: [],
     keywords: ''
   },
   // 输入框
   changeSearch: wx.$_.debounce(function ({
     detail
   }) {
     this.setData({
       keywords: detail.value
     })
     this.dataInit()
   }, 300),
   styleInit() {
     const self = this
     getElHeightRpx('#header', (height) => {
       self.setData({
         bodyHeight: app.globalData.viewHeight - height
       })
     })
   },
   // 数据初始化
   dataInit() {
     const self = this
     const {
       keywords,
       attributeList,
       attributeType,
       buildIdList,
       currStateList,
       degreeList,
       deptIdList,
       makeDeptIdList,
       makeTeamIdList,
       makeUserIdList,
       rangeTypeList,
       receiveWayList,
       repairEndTime,
       repairStartTime,
       sourceList,
     } = this.data
     const params = {
       keywords,
       attributeList,
       attributeType,
       buildIdList,
       currStateList,
       degreeList,
       deptIdList,
       makeDeptIdList,
       makeTeamIdList,
       makeUserIdList,
       rangeTypeList,
       receiveWayList,
       repairEndTime,
       repairStartTime,
       sourceList,
     }
     WorkOrderSearchApi.getList(params, (res) => {
       self.setData({
         dataList: res.data.rows
       })
     })

   },


   // 点击卡片
   onCard({
     detail
   }) {
     console.log(detail);
     const {
       id
     } = detail.value
     wx.navigateTo({
       url: `${SUB_PAGES.WorkOrder.WORK_ORDER_DETAIL.router}?orderId=${id}`
     })
   },
   // 点击筛选
   onFilter() {
     wx.navigateTo({
       url: `${SUB_PAGES.WorkOrder.WORK_ORDER_SEARCH_INDEX_FILTER.router}`
     })
   },

   // 滚动底部触发
   onScrollBottom() {

   },

   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
     this.styleInit()

     this.storeBindings = createStoreBindings(this, {
       store: workOrderSearchIndexFilterStore,
       fields: ['attributeList', 'attributeType', 'buildIdList', 'currStateList', 'degreeList', 'deptIdList', 'makeDeptIdList', 'makeTeamIdList', 'makeUserIdList', 'rangeTypeList', 'receiveWayList', 'repairEndTime', 'repairStartTime', 'sourceList', ]
     })
     this.storeBindings.updateStoreBindings()
     this.dataInit()
   },

   /**
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady() {

   },

   /**
    * 生命周期函数--监听页面显示
    */
   onShow() {

   },

   /**
    * 生命周期函数--监听页面隐藏
    */
   onHide() {

   },

   /**
    * 生命周期函数--监听页面卸载
    */
   onUnload() {
     this.storeBindings.destroyStoreBindings();
   },

   /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh() {

   },

   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom() {

   },

   /**
    * 用户点击右上角分享
    */
   onShareAppMessage() {

   }
 })